package com.eshop.modules.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.eshop.common.utils.QueryHelpPlus;
import com.eshop.modules.shop.service.dto.MaterialDto;
import java.util.LinkedHashMap;
import java.util.List;
import com.github.pagehelper.PageInfo;
import java.util.Map;
import org.springframework.data.domain.Pageable;
import com.eshop.modules.shop.service.dto.MaterialQueryCriteria;
import com.eshop.dozer.service.IGenerator;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.eshop.modules.shop.service.MaterialService;
import com.eshop.modules.shop.domain.Material;
import com.eshop.modules.shop.service.mapper.MaterialMapper;
import com.eshop.common.service.impl.BaseServiceImpl;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = { Exception.class })
public class MaterialServiceImpl extends BaseServiceImpl<MaterialMapper, Material> implements MaterialService
{
    private final IGenerator generator;
    
    public Map<String, Object> queryAll(final MaterialQueryCriteria criteria, final Pageable pageable) {
        this.getPage(pageable);
        final PageInfo<Material> page = (PageInfo<Material>)new PageInfo((List)this.queryAll(criteria));
        final Map<String, Object> map = new LinkedHashMap<String, Object>(2);
        map.put("content", this.generator.convert(page.getList(), (Class)MaterialDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }
    
    public List<Material> queryAll(final MaterialQueryCriteria criteria) {
        return (List<Material>)((MaterialMapper)this.baseMapper).selectList((Wrapper)QueryHelpPlus.getPredicate((Object)Material.class, (Object)criteria));
    }
    
    public MaterialServiceImpl(final IGenerator generator) {
        this.generator = generator;
    }
}
